import HDataTable from "@/components/ant-ext-table/HDataTable";
import HTag from "@/components/ant-ext/HTag";
import {UserStat, WithdrawalStat} from "@/const/const";
import {Form} from "antd";
import React from "react";
import {Dispatch} from "redux";
import {HTableProps} from "@/components/ant-ext-table/HTable";
import {useDispatch} from "react-redux";
import EntityWithdrawal from "@/api/entity-withdrawal";
import HAction from "@/components/common/HAction";
import {HDataTableSlice} from "@/components/ant-ext-table/redux/dataTableSlice";
import WithdrawalOpt from "@/pages/m-withdrawal/edit";

function getColumns(dispatch: Dispatch): HTableProps<any>["columns"] {
    return [
        {
            title: "ID",
            dataIndex: 'id',
            width: '100px',
            fixed: 'left',
        }, {
            title: "真实姓名",
            dataIndex: 'realName',
            render: (value, record) => {
                return record.stat !== "AWAIT" ? value : <HAction type={"link"}
                                                                  empower={EntityWithdrawal.OPT}
                                                                  invalid
                                                                  action={() => dispatch!(HDataTableSlice.actions.doAction({
                                                                      action: EntityWithdrawal.OPT,
                                                                      rowKey: EntityWithdrawal.RowKey,
                                                                      row: record
                                                                  }))}
                                                                  children={value}/>
            }
        }, {
            title: "状态",
            dataIndex: 'stat',
            render: (value: any) => <HTag value={value} mapping={WithdrawalStat.tag}/>
        }, {
            title: "提现金额",
            dataIndex: 'amount',
        }, {
            title: "银行卡号",
            dataIndex: 'bankNo',
        }, {
            title: "所属银行",
            dataIndex: 'bankName',
        }, {
            title: "支付宝账号",
            dataIndex: 'ali',
        }, {
            title: "创建时间",
            dataIndex: 'createTime',
        }
    ]
}

export default function Index() {
    const [form] = Form.useForm()
    const dispatch = useDispatch()

    return <>
        <WithdrawalOpt/>
        <HDataTable
            queryForm={{
                form: form,
                item: [
                    {name: "idName", label: "姓名"},
                    {name: "mobile", label: "电话号码"},
                    {name: "stat", label: "状态", type: "select", dataSource: UserStat.select, width: "150px"},
                ]
            }}
            columns={getColumns(dispatch)} selectMethod={EntityWithdrawal.selectTablePage}
            rowKey={"id"}
        />
    </>
}